package top.superflow.service.runtime

import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, ResponseBody, RestController}
import top.superflow.flow.runtime.cache.FlowRunTimeCache
import top.superflow.flow.runtime.flow.ExtFlow
import top.superflow.flow.runtime.mapper.RuntimeMapper
import top.superflow.flow.runtime.process.ExtProcess
import top.superflow.service.FlowManagerAware
import top.superflow.service.view.inf.WithAction

@RestController
@RequestMapping(Array("/runtime"))
class FlowRuntimeService extends FlowManagerAware{

  @RequestMapping(Array("/flow/all"))
  @ResponseBody
  def getAllFlow:  List[ExtFlow] = {
    val flows  = FlowRunTimeCache.getInstance.getAllFlow

    val flowList = toList[ExtFlow](flows)

    flowList.toList
  }


  @RequestMapping(Array("/process/all"))
  @ResponseBody
  def getAllProcess:  List[ ExtProcess] = {
    val process = FlowRunTimeCache.getInstance.getAllProcess

    toList(process).toList
  }

  @RequestMapping(Array("/mapper/all"))
  @ResponseBody
  def getAllMapper: List[ RuntimeMapper] = {
    val mappers = FlowRunTimeCache.getInstance.getAllMapper

    toList(mappers).toList
  }

  @RequestMapping(Array("/execute/flow/{group}/{flowKey}"))
  @ResponseBody
  def execute(@PathVariable group : String, @PathVariable flowKey : String):  Any = {
    flowManager.execute(group, flowKey)
  }

}

object
FlowRuntimeService {
  def main(args: Array[String]): Unit = {
    println(new ExtFlow with WithAction)
  }
}
